<!DOCTYPE html>
<html>
<!--
Copyright 2012 The Closure Library Authors. All Rights Reserved.

Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.

-->
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Closure Unit Tests - goog.storage.mechanism.ErrorHandlingMechanism</title>
<script src="../../base.js"></script>
<script>
  goog.require('goog.array');
  goog.require('goog.storage.mechanism.ErrorHandlingMechanism');
  goog.require('goog.testing.recordFunction');
  goog.require('goog.testing.jsunit');
</script>
</head>
<body>
<script>

var error = new Error();

var submechanism = {
  get: function() { throw error; },
  set: function() { throw error; },
  remove: function() { throw error; }
}

var handler = goog.testing.recordFunction(goog.nullFunction);
var mechanism;

function setUp() {
  mechanism = new goog.storage.mechanism.ErrorHandlingMechanism(
      submechanism, handler);
}

function tearDown() {
  handler.reset();
}

function testSet() {
  mechanism.set('foo', 'bar');
  assertEquals(1, handler.getCallCount());
  assertArrayEquals(
      [
        error,
        goog.storage.mechanism.ErrorHandlingMechanism.Operation.SET,
        'foo',
        'bar'
      ],
      handler.getLastCall().getArguments());
}

function testGet() {
  mechanism.get('foo');
  assertEquals(1, handler.getCallCount());
  assertArrayEquals(
      [
        error,
        goog.storage.mechanism.ErrorHandlingMechanism.Operation.GET,
        'foo'
      ],
      handler.getLastCall().getArguments());
}

function testRemove() {
  mechanism.remove('foo');
  assertEquals(1, handler.getCallCount());
  assertArrayEquals(
      [
        error,
        goog.storage.mechanism.ErrorHandlingMechanism.Operation.REMOVE,
        'foo'
      ],
      handler.getLastCall().getArguments());
}

</script>
</body>
</html>
